package de.gwtprime.client.event;

import com.google.gwt.event.shared.GwtEvent;

import de.gwtprime.client.event.handler.AuthenticationEventHandler;
import de.gwtprime.shared.UserDTO;

public class AuthenticationEvent extends GwtEvent<AuthenticationEventHandler>{

	public static Type<AuthenticationEventHandler> TYPE = new Type<AuthenticationEventHandler>();
	
	private UserDTO user;
	
	public enum AuthenticationEventType{
		LOGIN,
		LOGOUT
	}
	
	private AuthenticationEventType type;
	
	
	public AuthenticationEvent(AuthenticationEventType type){
		this(type, null);
	}
	
	public AuthenticationEvent(AuthenticationEventType type, UserDTO user){
		this.type = type;
		this.user = user;
	}
	
	@Override
	public Type<AuthenticationEventHandler> getAssociatedType() {
		return TYPE;
	}

	@Override
	protected void dispatch(AuthenticationEventHandler handler) {
		handler.onAuthenticationChange(this);
		
	}

	public AuthenticationEventType getType() {
		return type;
	}

	public void setType(AuthenticationEventType type) {
		this.type = type;
	}

	public UserDTO getUser() {
		return user;
	}

	public void setUser(UserDTO user) {
		this.user = user;
	}

}
